/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package expo43server;

import itopiamme.PhidgetHandler;
import java.net.*;
import java.io.*;

/**
 *
 * @author TommySprat
 */
public class Expo43GameServer extends Thread {

    ServerSocket serverSocket;
    Socket clientSocket;
    PhidgetHandler mainPhidgetHandler;

    public Expo43GameServer(PhidgetHandler mainPhidgetHandler) {
        this.mainPhidgetHandler = mainPhidgetHandler;
    }

    @Override
    public void run() {
        serverSocket = null;
        try {
            serverSocket = new ServerSocket(4447);
        } catch (IOException e) {
            System.err.println("Could not listen on port: 4447.");
            System.exit(1);
        }
        clientSocket = null;
        try {
            //Waits until a client connects on serverSocket
            clientSocket = serverSocket.accept();
            System.out.println("GameClient connected");
            mainPhidgetHandler.stopGame();
            serverSocket.close();
        } catch (IOException e) {
            System.err.println("Accept failed.");
            System.exit(1);
        }
    }
}
